﻿class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data: {
                tx: 0,
                txrate: 0,
                zb: 0,
                zhoubianrate: 0,
                thankrate: 0,
                winerate: 0,
                wine: 0
            },


        };
    }














    getdata() {
        let that = this

        获取设置(res => {
            if (res.issuccess == 1) {
                //  let { tx, txrate, zb,zbrate,wine,winerate,thankrate  } = res.data
                that.setState({ data: res.data })
            }
        })
    }


    componentDidMount() {
        let sizehtml = [], pricehtml = [], { sizelist, pricelist } = this.state

        this.getdata()


        $('.modal1').hide()
        // testdingcan(res=>{
        // })
        this.setState({ showloading: '' })
        // this.freshlist()

    }

    add() {
        let { data } = this.state, that = this, err = '';
        if (isNaN(data.wine) || data.wine < 0) err = '请输入正确的联名酒数量'
        if (isNaN(data.zb) || data.zb < 0) err = '请输入正确的周边数量'
        if (isNaN(data.tx) || data.tx < 0) err = '请输入正确的季卡数量'
        if (isNaN(data.txrate) || data.txrate < 0||data.txrate>1000) err = '请输入正确的季卡概率'
        if (isNaN(data.winerate)|| data.winerate < 0||data.winerate>1000) err = '请输入正确的联名酒概率'
        if (isNaN(data.zhoubianrate)|| data.zhoubianrate < 0||data.zhoubianrate>1000) err = '请输入正确的周边概率'
        if (isNaN(data.thankrate)|| data.thankrate < 0||data.thankrate>1000) err = '请输入正确的未中奖概率'

        if (err != '') {
            alert(err)
        } else {
         //   console.log(data,'data111');

           // let data = { wine, zb, shop_dakascore, now_smallprobability, now_bigprobability }
          
          
           编辑设置(data, res => {
                if (res.issuccess == 1) {
                    alert('保存成功')

                }
            })

            console.log(data, 'itemm');



            // 添加账号({ shopname: item.name, shopid: item.id, shopnum: select_usernum }, res => {
            //     $('.modal1').hide()
            //     if (res.issuccess == 1) {
            //         that.getdata()

            //     }
            // })

            // 添加账号({desc,name:username,pwd:md5(pwd + Constant.SALT).toUpperCase(),realpwd:pwd},res=>{
            //     $('.modal1').hide() 
            //     if(res.issuccess==1){
            //         that.getdata()
            //     }else{
            //         alert(res.msg)
            //     }
            // })
        }

    }




    inputchange(prop, e) {
        let {data} = this.state
        data[prop]= e.target.value
        this.setState({ data })
    }
    inputchange1(prop, id, e) {
        let that = this;
        if (prop == "state") {
            that.setState({ showloading: 'ON' })
            Shopsetstate(id, res => {
                if (res.issuccess == 1) {
                    alert("设置成功")
                    that.freshlist()
                } else {
                    that.setState({ showloading: '' })
                    alert(res.msg)
                }
            })
        } else if (prop == "isrecommend") {
            that.setState({ showloading: 'ON' })
            Shopsetrecommend(id, res => {
                if (res.issuccess == 1) {
                    alert("设置成功")
                    that.freshlist()
                } else {
                    that.setState({ showloading: '' })
                    alert(res.msg)
                }
            })
        }

    }


    selectchange(prop, e) {
        this.setState({ [prop]: e.target.value }, () => {
            this.search()
        })
    }



    selectfhchange(e) {
        console.log(e.target.value, 'selectfhchange');
        this.setState({ select_shop: e.target.value })
    }



    jiebang(id) {

        var a = confirm('确定要解绑吗?'), that = this
        if (a) {
            解绑(id, res => {
                if (res.issuccess == 1) {
                    that.getdata()
                }
            })
        }
    }


    render() {
        let { data } = this.state;

        return (
            <div className="breadLinebox">
                <div class="alertarea" id='alsucc' >
                </div>


                <Loading hidden={this.state.showloading != 'ON'} />


                <div className='panel-default content_wrap'>
                    <div className="breadLine ">

                        <view className="wrap">

                            <div className="content">
                                <p className="p1">联名酒数量</p>
                                <antd.Input placeholder="请输入联名酒数量" allowClear value={data.wine} onChange={this.inputchange.bind(this, 'wine')} className="input" />
                            </div>
                            <div className="content">
                                <p className="p1">联名酒概率（1-1000整数）</p>
                                <antd.Input placeholder="请输入联名酒概率" allowClear value={data.winerate} onChange={this.inputchange.bind(this, 'winerate')} className="input" />
                            </div>
                             <div className="content">
                                <p className="p1">腾讯季卡数量</p>
                                <antd.Input placeholder="请输入腾讯季卡数量" allowClear value={data.tx} onChange={this.inputchange.bind(this, 'tx')} className="input" />
                            </div>
                            <div className="content">
                                <p className="p1">腾讯季卡概率（1-1000整数）</p>
                                <antd.Input placeholder="请输入腾讯季卡概率" allowClear value={data.txrate} onChange={this.inputchange.bind(this, 'txrate')} className="input" />
                            </div>
                              <div className="content">
                                <p className="p1">钥匙扣数量</p>
                                <antd.Input placeholder="请输入钥匙扣数量" allowClear value={data.zb} onChange={this.inputchange.bind(this, 'zb')} className="input" />
                            </div>
                            <div className="content">
                                <p className="p1">钥匙扣概率（1-1000整数）</p>
                                <antd.Input placeholder="请输入钥匙扣概率" allowClear value={data.zhoubianrate} onChange={this.inputchange.bind(this, 'zhoubianrate')} className="input" />
                            </div>
                             <div className="content">
                                <p className="p1">未中奖概率（1-1000整数）</p>
                                <antd.Input placeholder="请输入未中奖概率" allowClear value={data.thankrate} onChange={this.inputchange.bind(this, 'thankrate')} className="input" />
                            </div>

                            {/* 
                        <div className="content">
                            <p className="p1">打卡积分</p>
                            <antd.Input placeholder="请输入联名酒数量" allowClear value={} onChange={this.inputchange.bind(this, 'shop_dakascore')} className="input" />
                        </div>


                        <div className="content">
                            <p className="p1">100积分抽奖概率（1-100整数）</p>
                            <antd.Input placeholder="请输入惊喜礼盒概率" allowClear value={} onChange={this.inputchange.bind(this, 'now_smallprobability')} className="input" />
                        </div>

                        <div className="content">
                            <p className="p1">1000积分抽奖概率（1-100整数）</p>
                            <antd.Input placeholder="请输入惊喜礼盒概率" allowClear value={} onChange={this.inputchange.bind(this, 'now_bigprobability')} className="input" />
                        </div> */}

                            <view className="button" onClick={this.add.bind(this)}>保存</view>



                        </view>



                    </div>


                </div>
            </div>


        )


    }
}

ReactDOM.render(
    <div>
        <TopLine />
        <div id='body'>
            <LeftMenu code='settings' height='settings' />
            <Main />
        </div>
    </div>
    // <Barrage/>
    , $('.container')[0]
)